package gameoflife;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class CellTest {

	@Test
	public void cellHasOnTheRightSideANeighbour() throws Exception {
		Cell cell = new Cell(0, 0);
		assertTrue(cell.isNeighbourOf(1, 0));
	}

	@Test
	public void cellHasNotANeighbourOnTheRightSide() throws Exception {
		Cell cell = new Cell(0, 0);
		assertFalse(cell.isNeighbourOf(2, 0));
	}

	@Test
	public void cellHasAboveANeighbour() throws Exception {
		Cell cell = new Cell(0, 0);
		assertTrue(cell.isNeighbourOf(0, 1));
	}

	@Test
	public void cellHasNotAboveANeighbour() throws Exception {
		Cell cell = new Cell(0, 0);
		assertFalse(cell.isNeighbourOf(0, 2));
	}

	@Test
	public void cellHasANeigbhourOnTheRightUpDiagonal() throws Exception {
		Cell cell = new Cell(0, 0);
		assertTrue(cell.isNeighbourOf(1, 1));
	}

	@Test
	public void cellHasNotANeighbourOnTheRightUpDiagonal() throws Exception {
		Cell cell = new Cell(0, 0);
		assertFalse(cell.isNeighbourOf(2, 2));
	}

	@Test
	public void cellShouldHaveEightNeighbours() throws Exception {
		Cell cell = new Cell(1, 1);
		assertTrue(cell.isNeighbourOf(0, 0));
		assertTrue(cell.isNeighbourOf(1, 0));
		assertTrue(cell.isNeighbourOf(2, 0));
		assertTrue(cell.isNeighbourOf(1, 2));
		assertTrue(cell.isNeighbourOf(2, 0));
		assertTrue(cell.isNeighbourOf(2, 1));
		assertTrue(cell.isNeighbourOf(2, 2));
	}

	@Test
	public void cellShouldNotHaveAnyNeighbours() throws Exception {
		Cell cell = new Cell(2, 2);
		assertFalse(cell.isNeighbourOf(0, 0));
		assertFalse(cell.isNeighbourOf(1, 0));
		assertFalse(cell.isNeighbourOf(2, 0));
		assertFalse(cell.isNeighbourOf(3, 0));
		assertFalse(cell.isNeighbourOf(4, 0));
	}

	@Test
	public void cellIsNotANeighbourForItSelf() throws Exception {
		Cell cell = new Cell(0, 0);
		assertFalse(cell.isNeighbourOf(0, 0));
	}

	@Test
	public void cellsOnTheSamePositionAreEquals() throws Exception {
		Cell cell = new Cell(1, 1);
		assertThat(cell.equals(1, 1), is(true));
		assertThat(cell.equals(2, 1), is(false));
	}
}
